﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaxLeaf.Common;
using MaxLeaf.DB;
using System.Data;
using MySql.Data.MySqlClient;

namespace MaxLeaf.DAL.Web
{
   /// <summary>
   /// 职员
   /// </summary>
    public class t_Base_EmpDAL : BaseDAL
    {
        public t_Base_EmpDAL()
            : base()
        {
            strTableName = "mary_t_Base_Emp";
            strKeyFieldName = "FItemID";
            strFieldNames = "FGender,FBirthday,FEmail,FAddress,FPhone,FID,FDuty,FDegree,FHireDate,FLeaveDate,FEmpGroupID,FItemDepID,FBankID,FBankAccount,FNote,FBrNO,FName,FParentID,FDeleted,FDepartmentID,FEmpGroup,FNumber,FShortNumber,FIsCreditMgr,FCreditPeriod,FCreditLevel,FProfessionalGroup,FOperationGroup,FJobTypeID,FAllotPercent,FCreditDays,FCreditAmount,FOtherARAcctID,FOtherAPAcctID,FPreARAcctID,FPreAPAcctID,FMobilePhone";
        }
        protected override void DAL_GetFieldData(DBAccess dbOrgCon, DBAccess dbDestCon, string strFieldName, DataRow drOrgData, DataRow drDestData)
        {
            if (strFieldName.Equals("FDepartmentID", StringComparison.InvariantCultureIgnoreCase))
            {

                string strFUnitGroupID = GetFDepartmentID(dbOrgCon, dbDestCon, CvtFunc.ToString(drOrgData[strFieldName]));
                if (strFUnitGroupID.Length == 0)
                {
                    drDestData[strFieldName] = DBNull.Value;
                }
                else
                {
                    drDestData[strFieldName] = strFUnitGroupID;


                }

            }
            else
            {
                base.DAL_GetFieldData(dbOrgCon, dbDestCon, strFieldName, drOrgData, drDestData);
            }
        }

        private string GetFDepartmentID(DBAccess dbOrgCon, DBAccess dbDestCon, string strOrgFDepartmentID)
        {
            t_departmentDAL dal = new t_departmentDAL();


            return dal.FDepartmentID(dbOrgCon, dbDestCon, strOrgFDepartmentID);


        }

        protected override DataTable DAL_GetData(DBAccess dbOrgCon, DBAccess destCon, int intdataType, object objParam)
        {
            GetDataType dataType = (GetDataType)intdataType;

            if (dataType == GetDataType.OrgData)
            {
                return Gett_Base_Emp(dbOrgCon, CvtFunc.ToString(objParam));
            }


            return base.DAL_GetData(dbOrgCon, destCon, intdataType, objParam);
        }


        
        private DataTable Gett_Base_Emp(DBAccess dbOrgCon, string strFItemID)
        {
            DataTable dtt_Base_Emp = null;
            if (dtt_Base_Emp == null)
            {
                dtt_Base_Emp = dbOrgCon.GetTableData("t_Base_Emp", new Dictionary<string, object> { { "FItemID", strFItemID } });

            }
            return dtt_Base_Emp;
        }
    }
}